{% extends "base.html" %}
{% block js %}
    <script>
        $(document).ready(function () {
        });
    </script>
{% endblock %}
{% block content %}
    <div class="container">
        {% for post in posts %}
            <div class="post">
                <div class="postheader">
                    <div class="date shadow">
                        <span class="year">{{post.post_date|date:"j-m-o" }}</span>
                        <span class="time">{{ post.post_date|time:"TIME_FORMAT" }}</span>
                    </div>
                </div>
                <div class="postcontent">
                    <h2>
                        <a href="{% url view_single_article post.id %}">{{ post.title }}</a>
                        <input class="readmore" value="Đọc thêm" type="button"/>
                    </h2>
                    <div class="postinfo">

                        {% if post.account_id %}
                            <span class="author">Viết bởi <a href="{% url view_posts_by_account post.account_id.id %}">{{ post.account_id|default_if_none:"Giấu tên" }}</a></span>
                        {% else %}
                            <span class="author">Viết bởi <a href="{% url view_posts_by_account 0 %}">{{ post.account_id|default_if_none:"Giấu tên" }}</a></span>
                        {% endif %}
                        {% if post.category_id %}
                            <span class="category">Nhóm <a href="{% url view_posts_in_category post.category_id.id%}">{{ post.category_id.name|default_if_none:"Không phân nhóm" }}</a></span>
                        {% else %}
                            <span  class="category">Nhóm <a href="{% url view_posts_in_category 0 %}">{{ post.category_id.name|default_if_none:"Không phân nhóm" }}</a></span>
                        {% endif %}
                    </div>

                    <div class="content">
                    {{ post.content|safe }}
                    </div>
                </div>
            </div>
        {% endfor %}
        {% if post.number > 1 or posts.has_next%}
        <div class="pagination">
            <span class="step-links">
                {% if posts.has_previous %}
                    <a href="?page={{ posts.previous_page_number }}">Trang trước</a>
                {% endif %}

                <span class="current">
                    Trang {{ posts.number }} / {{ posts.paginator.num_pages }}.
                </span>

                {% if posts.has_next %}
                    <a href="?page={{ posts.next_page_number }}">Trang sau</a>
                {% endif %}
            </span>
        </div>
        {% endif %}
    </div>
{% endblock %}